import { _decorator, Component, Node } from "cc";
const { ccclass, property } = _decorator;

@ccclass("Bg")
export class Bg extends Component {
  @property(Node)
  public bg1: Node | null = null;

  @property(Node)
  public bg2: Node | null = null;

  public bg3: Node | null = null;

  private speed: number = 120;

  start() {}

  update(deltaTime: number) {
    this.bg1.setPosition(
      this.bg1.position.x,
      this.bg1.position.y - this.speed * deltaTime,
      this.bg1.position.z
    );
    this.bg2.setPosition(
      this.bg2.position.x,
      this.bg2.position.y - this.speed * deltaTime,
      this.bg2.position.z
    );

    if (this.bg1.position.y < -852) {
      this.bg1.setPosition(0, this.bg2.position.y + 852, 0);
    }

    if (this.bg2.position.y < -852) {
      this.bg2.setPosition(0, this.bg1.position.y + 852, 0);
    }
  }
}
